package com.niit.controller.example;

import java.sql.*;

public class RetrieveData {
    private static String driverClass = "org.apache.hive.jdbc.HiveDriver";
    public static void main(String[] args) throws SQLException {
        try {
            Class.forName(driverClass);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection connection = DriverManager.getConnection("jdbc:hive2://niit-china:10000/default","root","singh321");
        Statement statement = connection.createStatement();
        String table_name ="dept";
        String query = "select * from "+table_name;
        ResultSet result = statement.executeQuery(query);
        System.out.println("Table Data is :");
        while(result.next())
        {
            System.out.println("col1 : "+result.getInt(1));
            System.out.println("col2 : "+result.getString(2));
            System.out.println("col3 : "+result.getString(3));
            System.out.println("col4 : "+result.getInt(4));

        }
        result.close();
        statement.close();
        connection.close();

    }
}
